package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 石小俊
 */
@WebServlet("/method")
public class MethodServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 常用请求方法
        // 1.获取浏览器请求地址中应用名后面的路径
        // 相当于url-pattern,通配符方式除外
        String servletPath = req.getServletPath();
        System.out.println("servletPath:" + servletPath);

        // 2.获取应用名
        String contextPath = req.getContextPath();
        System.out.println("contextPath:" + contextPath);

        // 3.获取uri地址,即:浏览器地址栏端口号后面的路径
        String uri = req.getRequestURI();
        System.out.println("uri:" + uri);

        // 4.获取url地址,即:浏览器地址栏完整地址
        StringBuffer url = req.getRequestURL();
        System.out.println("url:" + url);

        // 5.获取访问者的ip地址,即:访问当前服务器资源的用户的ip地址
        String ip = req.getRemoteAddr();
        System.out.println("ip:" + ip);
    }
}
